package com.luckku.boot.service.impl;



import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.luckku.boot.mapper.GoodsStoreMapper;
import com.luckku.boot.model.entity.Goods;
import com.luckku.boot.mapper.GoodsMapper;
import com.luckku.boot.model.entity.GoodsStore;
import com.luckku.boot.service.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author luckku
 * @date 2021/8/14
 */

@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements IGoodsService {

    @Autowired
    GoodsMapper goodsMapper;
    @Autowired
    GoodsStoreMapper goodsStoreMapper;

    @Override
    public Long getPriceById(String goodsId) {
        Goods goods = goodsMapper.selectById(goodsId);
        return goods.getPrice();
    }

    @Override
    public List<Goods> getGoodsList(boolean isTop) {
        if (isTop) {
            return goodsMapper.getGoodsListTop();
        }
        return goodsMapper.getGoodsListBottom();
    }

    @Override
    public List<Goods> getByStrLike(String column, String str) {
        return goodsMapper.selectList(new QueryWrapper<Goods>().like(column,str));
    }

    @Override
    public List<Goods> getByStrExact(String column, String str) {
        return goodsMapper.selectList(new QueryWrapper<Goods>().eq(column,str));
    }

    @Override
    public Page<GoodsStore> getList(Page<GoodsStore> page, String storeId) {
        return goodsStoreMapper.selectPage(page,new QueryWrapper<GoodsStore>().eq("store_id", storeId));
    }

    @Override
    public Page<Goods> getUnstoreList(Page<Goods> page) {
        return goodsStoreMapper.selectUnstoreList(page);
    }

    @Override
    public Goods getSeckillGoods(String goodsId) {
        return goodsMapper.getSeckillGoods(goodsId);
    }
}
